import axios from "axios";

//eslint-disable-next-line
export default {
    login: ({ username, password, phone }) =>
        axios.get('/api/users/login', {
            params: { username, password, phone }
        })
            .then(({ data }) => data),
    reg: ({ username, password, phone }) =>
        axios.post('/api/users/reg', {
            username, password, phone
        })
            .then(({ data }) => data),

    // 获取每页数据
    get: ({ curPage, eachPage }) =>
        axios.get('/api/users', {
            params: {
                curPage,
                eachPage
            }
        }).then(({ data }) => data),

    // 删除
    delete: ({ _id }) =>
        axios.delete(`/api/users`, {
            data: {
                _id
            }
        }).then(({ data }) => data),

    // 查询数据
    find: ({ username }) => axios.get(`/api/users/getsearch`, {
        params: { username }
    }).then(({ data }) => data),

    // 保存令牌
    setToken: token => (localStorage["_t"] = token),
    // 获取令牌
    getToken: () => localStorage["_t"]
}